﻿@*编辑作业页面*@
@using EasyCourse.Model;
@using EasyCourse.DB;
@model VAssignmentInfo
@{
    Layout = null;
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
    string para = "CourseId=" + pageInfo.CourseId;
}
 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>编辑作业</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
    <link href="../Content/bootstrap/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" media="all" href="../css/daterangepicker-bs3.css" />
    
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav4Teacher.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">@pageInfo.CourseName<br><small>广州中医药大学康复治疗微课程网络学习平台</small></h1>
        </div>
    </div>
    @*导航菜单*@
    @Html.Partial("~/Views/Share/PublicTeacherNaviMenu.cshtml", 1)
    <div class="container">
        <div class="row">
            <div class="col-xs-2">
                <div class="dropdown theme-dropdown clearfix">
                    <a id="dropdownMenu1" href="#" role="button" class="sr-only dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                        <li role="presentation">
                            <a role="menuitem" tabindex="-1" href="/AssignmentManage/List?@para">
                                <span class="glyphicon glyphicon-th-list"></span> 作业列表
                            </a>
                        </li>
                        <li role="presentation" class="divider"></li>
                        <li class="active" role="presentation">
                            <a role="menuitem" tabindex="-1" href="javascript:void(0)">
                                <span class="glyphicon glyphicon-plus"></span> 新增作业
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="col-xs-10">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <ol class="breadcrumb">
                                <li>作业管理</li>
                                <li class="active"> 编辑作业</li>
                            </ol>
                        </h3>
                    </div>
                    <div class="panel-body" style="height:610px;">
                        <div class="row">
                            <form role="form" class="form-horizontal">
                                <div class="form-group clearfix">
                                    <label for="courseTitle" class="col-xs-2 control-label">作业标题：</label>
                                    <div class="col-xs-4">
                                        <input value="@Model.Entity.Title" type="text" class="form-control input-md" id="courseTitle" placeholder="请输入作业名称">
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="stuGroup" class="col-xs-2 control-label">学生组：</label>
                                    <div class="col-xs-4">
                                        <button type="button" data-target="#myModal" class="btn dropdown-toggle" id="studentsGroup" data-toggle="modal"><span class="groupName" data="@Model.Entity.GroupId">@Model.GroupName</span> <span class="caret"></span>
   </button>
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="workIntro" class="col-xs-2 control-label">作业简介：</label>
                                    <div class="col-xs-10">
                                        <textarea class="form-control" rows="6" id="workIntro">@Model.Entity.Remark</textarea>
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="JfileName" class="col-xs-2 control-label">作业附件：</label>
                                    <div class="col-xs-4">
                                        <input name="fileName"  data-fileUrl="@Model.Entity.AttachmentUrl" value="@Model.AttachmentFileName" id="JfileName" class="form-control mb10" readonly="readonly" />                                            
                                        <input id="file_upload" name="file_upload" type="file" class="form-control input-sm">
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="releaseState" class="col-xs-2 control-label">是否发布：</label>
                                    <div class="col-xs-4">
                                        <select class="form-control" id="releaseState">
                                            @if (Model.Entity.Status == 1)
                                            {
                                                <option value="0">否</option>
                                                <option value="1" selected>是</option>
                                            }
                                            else
                                            {
                                                <option value="0" selected>否</option>
                                                <option value="1">是</option>
                                            }

                                        </select>
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="deadline" class="col-xs-2 control-label">截止时间：</label>
                                    <div class="col-xs-4">
                                        <div class="input-prepend input-group">
                                            <span class="add-on input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
                                            <input type="text" name="deadline" id="deadline" class="form-control" value="@Model.Entity.DeadTime.ToTimeString("{0:f}",true)" />
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <div class="col-xs-offset-2 col-xs-10">
                                        <button type="button" class="btn btn-success" id="saveBtn">保存</button>
                                        <button type="button" onclick="history.go(-1)" class="btn btn-success btn-md"><span class="glyphicon glyphicon-arrow-left"></span>返回</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--学生组弹出框-->
    <div class="modal fade custom" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h5 class="modal-title" id="myModalLabel">学生组名</h5>
                </div>
                <div class="modal-body">
                    <form role="form">
                        <div class="row">
                            <div class="col-xs-8">
                                <div class="form-group">
                                    <input type="text" id="studentG" class="form-control input-sm" placeholder="请输入学生组名" />
                                </div>
                            </div>
                            <div class="col-xs-4"><button type="button" class="btn btn-sm btn-success" id="searchSG">搜索</button></div>
                        </div>
                    </form>
                    <div class="resultList" id="resultList">
                        <ul class="list-group" id="listgroup1"></ul>
                        <div class="clearfix" id="well">
                            <div class="pull-left sum" id="PagInfo"></div>
                            <div class=" center-block clearfix pull-right">
                                <ul class="pagination" id="PageTool"></ul>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary btn-sm" id="confirmGrpName">确定</button>
                    <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">取消</button>
                </div>
            </div><!-- /.modal-content -->
        </div>
    </div><!-- /.modal -->
    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")
    @*<script type="text/javascript" src="../Content/uploadify/jquery.uploadify.min.js?v=@DateTime.Now.Ticks"></script>*@
    <!--moment.js与daterangepicker.js为日历插件-->
    <script src="../Content/datepicker/moment.js"></script>
    <script src="../Content/datepicker/daterangepicker.js"></script>
    <script src="../Js/uploadToggle.js"></script>
    <script>
        var $listgroup1;
        $(function () {
            $listgroup1 = $("#listgroup1");
            $(window).scroll(function () {
                if ($(window).scrollTop() >= 300) {
                    $('.actGotop').fadeIn(300);
                } else {
                    $('.actGotop').fadeOut(300);
                }
            });
            //上传文件
            var _attachmentUrl = null;
            uploadToggle('@Url.Action("UpLoad","Base")', { 'fileType': 'OtherFile' }, function (file, data) {
                var json = $.parseJSON(data);
                if (json.result) {
                    _attachmentUrl = json.message; //文件保存的地址
                    $("#JfileName").val(file.name);
                    $("#JfileName").attr("data-fileUrl", _attachmentUrl);
                }
                else {
                    showTips.open(json.message);
                }
            });
           
            //提交作业修改
            $("#saveBtn").bind("click", function () {
                var Jfile = $("#JfileName").attr("data-fileUrl"),  //作业附件
                    courseTitle = $("#courseTitle").val(),
                    studentsGroup = $("#studentsGroup .groupName").attr("data"),
                    courseIntro = $("#workIntro").val(),
                    releaseState = $("#releaseState").val();  //是否发布
                deadline = $("#deadline").val(),   //截止时间
                courseId = $.getUrlParam("CourseId");
                $.easyPost("@Url.Action("ModifyAssignment","AssignmentManage")", {
                    "Title": courseTitle,
                    "Remark": courseIntro,
                    "GroupId": studentsGroup,
                    "AttachmentUrl": Jfile,
                    "CourseId": $.getUrlParam("CourseId"),
                    "Status": releaseState,
                    "DeadTime": deadline,
                    "Id": $.getUrlParam("AssignmentId")
                }, function (data) {
                    if (data.result) {
                        showTips.open("保存成功！");
                        return;
                    } else {
                        showTips.open(data.message);
                        return;
                    }
                }, "json")
            });
            $('.actGotop').click(function () { $('html,body').animate({ scrollTop: '0px' }, 800); });
            $('#deadline').daterangepicker({ singleDatePicker: true, format: 'YYYY/MM/DD h:mm A', timePicker: true }, function (start, end, label) {

            });
            getResults(1);
            //模态框查询，每次开启新查询，初始化一次模态框（即输入框，查询列表初始化）
            $("#searchSG").bind("click", function () {
                //若无数据，则提示没有匹配的学生组，若有数据则解析
                getResults(1);
            });
            $listgroup1.delegate("li", "click", function () {
                $(this).addClass("active").siblings().removeClass("active");
            });
            //确定按钮点击之后，赋予学生组选择按钮选中的值，并关闭模态框。
            $("#confirmGrpName").bind("click", function () {
                var tmpEle = $listgroup1.find(".active");
                if (tmpEle.size == 0) { showTips.open("您并未选中中任何学生组"); return; }
                searchId = tmpEle.attr("data");
                searchtxt = tmpEle.text();  /*对应的id如何处理*/
                $("#studentsGroup .groupName").text(searchtxt).attr("data", searchId);
                $("#myModal").modal("hide");
            });
        });
        function getResults(pageNo) {
            GrpName = $("#studentG").val().trim();
            $.easyPost("@Url.Action("GetGrpList","GrpManage")", { "PageNO": pageNo, "PageSize": 10, "GrpName": GrpName }, function (data) {
                var _html = "";
                if (!data.result) {
                    showTips.open(data.message); return;
                }
                if (data.rows.length > 0) {
                    var _rows = data.rows, _rowL = _rows.length;
                    opts = {
                        totalPages: data.totalPage,
                        total: data.total,
                        currentPage: pageNo,
                        onPageClicked: function (event, originalEvent, type, page) {
                            getResults(page);
                        }
                    };
                    initialPaginator(opts, "PageTool", "PageInfo");
                    for (var i = 0; i < _rowL; i++) {
                        var item = _rows[i];
                        _html += '<li data="' + item.Entity.Id + '" class="list-group-item">' + item.Entity.GroupName + '</li>';
                    }
                    $("#well").show();
                }
                else { _html = '<li style="text-align:center">没有搜索到匹配项</li>'; $("#well").hide(); }
                $listgroup1.html(_html);

            });
        }
    </script>
</body>
</html>